<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>gojs入门学习 | Jaho’s Blog</title>
    <meta name="generator" content="VuePress 1.8.0">
    <link rel="icon" href="/favicon.ico">
    <link rel="manifest" href="/manifest.json">
    <meta name="description" content="记录日常学习工作">
    
    <link rel="preload" href="/assets/css/0.styles.5b8fe0a4.css" as="style"><link rel="preload" href="/assets/js/app.6514719e.js" as="script"><link rel="preload" href="/assets/js/2.ea114ffb.js" as="script"><link rel="preload" href="/assets/js/45.870a7650.js" as="script"><link rel="preload" href="/assets/js/4.e093c564.js" as="script"><link rel="prefetch" href="/assets/js/10.13203aa5.js"><link rel="prefetch" href="/assets/js/11.099868c4.js"><link rel="prefetch" href="/assets/js/12.c8365e17.js"><link rel="prefetch" href="/assets/js/13.89751e7c.js"><link rel="prefetch" href="/assets/js/14.31f563eb.js"><link rel="prefetch" href="/assets/js/15.08b381b6.js"><link rel="prefetch" href="/assets/js/16.1a3867de.js"><link rel="prefetch" href="/assets/js/17.7dd4e0c6.js"><link rel="prefetch" href="/assets/js/18.907c4597.js"><link rel="prefetch" href="/assets/js/19.fac8aa1a.js"><link rel="prefetch" href="/assets/js/20.73fe0e75.js"><link rel="prefetch" href="/assets/js/21.5c50aa1c.js"><link rel="prefetch" href="/assets/js/22.83d03663.js"><link rel="prefetch" href="/assets/js/23.061e7ac0.js"><link rel="prefetch" href="/assets/js/24.cc7e9011.js"><link rel="prefetch" href="/assets/js/25.fa6c7aef.js"><link rel="prefetch" href="/assets/js/26.39392f70.js"><link rel="prefetch" href="/assets/js/27.204436be.js"><link rel="prefetch" href="/assets/js/28.3f54c157.js"><link rel="prefetch" href="/assets/js/29.799d048c.js"><link rel="prefetch" href="/assets/js/3.6c5d6214.js"><link rel="prefetch" href="/assets/js/30.deed02f3.js"><link rel="prefetch" href="/assets/js/31.5916873b.js"><link rel="prefetch" href="/assets/js/32.b0634144.js"><link rel="prefetch" href="/assets/js/33.734675b8.js"><link rel="prefetch" href="/assets/js/34.20404dc4.js"><link rel="prefetch" href="/assets/js/35.d93b829f.js"><link rel="prefetch" href="/assets/js/36.b0692d8d.js"><link rel="prefetch" href="/assets/js/37.3dffa306.js"><link rel="prefetch" href="/assets/js/38.04649a97.js"><link rel="prefetch" href="/assets/js/39.7dfcdc32.js"><link rel="prefetch" href="/assets/js/40.04914511.js"><link rel="prefetch" href="/assets/js/41.ced85449.js"><link rel="prefetch" href="/assets/js/42.72739213.js"><link rel="prefetch" href="/assets/js/43.de1cff16.js"><link rel="prefetch" href="/assets/js/44.48e301ae.js"><link rel="prefetch" href="/assets/js/46.657f15b8.js"><link rel="prefetch" href="/assets/js/47.3df1bfdb.js"><link rel="prefetch" href="/assets/js/48.f4e4e774.js"><link rel="prefetch" href="/assets/js/49.632bf611.js"><link rel="prefetch" href="/assets/js/5.6531e181.js"><link rel="prefetch" href="/assets/js/50.a8018493.js"><link rel="prefetch" href="/assets/js/51.cb424f59.js"><link rel="prefetch" href="/assets/js/52.a9f595dc.js"><link rel="prefetch" href="/assets/js/53.cf8a9ec0.js"><link rel="prefetch" href="/assets/js/54.46d774a3.js"><link rel="prefetch" href="/assets/js/55.3574f9b8.js"><link rel="prefetch" href="/assets/js/56.baf60ba5.js"><link rel="prefetch" href="/assets/js/57.af42b559.js"><link rel="prefetch" href="/assets/js/58.9300cb59.js"><link rel="prefetch" href="/assets/js/6.00f437ec.js"><link rel="prefetch" href="/assets/js/7.58ac7166.js"><link rel="prefetch" href="/assets/js/8.1b9c5002.js"><link rel="prefetch" href="/assets/js/9.5c076362.js">
    <link rel="stylesheet" href="/assets/css/0.styles.5b8fe0a4.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="Jaho’s Blog" class="logo"> <span class="site-name can-hide">Jaho’s Blog</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/posts/" class="nav-link router-link-active">
  技术博客
</a></div> <a href="https://juejin.cn/user/26836627369806" target="_blank" rel="noopener noreferrer" class="repo-link">
    个人主页
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/posts/" class="nav-link router-link-active">
  技术博客
</a></div> <a href="https://juejin.cn/user/26836627369806" target="_blank" rel="noopener noreferrer" class="repo-link">
    个人主页
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><a href="/posts/" aria-current="page" class="sidebar-link">写在前面</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>工作问题解决</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/posts/项目问题解决/vuevite.html" class="sidebar-link">vue3+vite用proxy解决跨域及proxy原理解析</a></li><li><a href="/posts/项目问题解决/大文件.html" class="sidebar-link">大文件切片上传和断点续传</a></li><li><a href="/posts/项目问题解决/代码优化.html" class="sidebar-link">实际工作中代码优化</a></li><li><a href="/posts/项目问题解决/组件问题.html" class="sidebar-link">解决组件传值问题</a></li><li><a href="/posts/项目问题解决/动态组件.html" class="sidebar-link">动态组件实践</a></li><li><a href="/posts/项目问题解决/大屏.html" class="sidebar-link">大屏九宫格视频</a></li><li><a href="/posts/项目问题解决/滚动.html" class="sidebar-link">Vue中Element表单定位滚动到校验错误位置</a></li><li><a href="/posts/项目问题解决/红绿灯.html" class="sidebar-link">Promise实现动态红绿灯切换</a></li><li><a href="/posts/项目问题解决/懒加载.html" class="sidebar-link">实现元素懒加载</a></li><li><a href="/posts/项目问题解决/小程序组件.html" class="sidebar-link">微信小程序封装组件</a></li><li><a href="/posts/项目问题解决/axios.html" class="sidebar-link">项目中对axios的整体封装</a></li><li><a href="/posts/项目问题解决/docker.html" class="sidebar-link">docker实践(附windows安装下载教程)</a></li><li><a href="/posts/项目问题解决/eltable.html" class="sidebar-link">el-table自定义表头及无数据状态</a></li><li><a href="/posts/项目问题解决/gojs.html" class="active sidebar-link">gojs入门学习</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/posts/项目问题解决/react踩坑.html" class="sidebar-link">React踩坑</a></li><li><a href="/posts/项目问题解决/小程序踩坑.html" class="sidebar-link">小程序踩坑</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>JavaScript</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Css</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Nodejs</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Vue</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Git</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="gojs入门学习"><a href="#gojs入门学习" class="header-anchor">#</a> gojs入门学习</h1> <blockquote><p>gojs是一个用于构建交互式图表和图形的 JavaScript 和 TypeScript 库。GoJS 允许您为您的用户构建各种图表和图形，从简单的流程图和组织结构图到高度具体的工业图、SCADA 和 BPMN 图、像基因图这样的医学图等等。GoJS 使用可定制的模板和布局使构建复杂节点、链接和组的 JavaScript 图表变得容易。</p> <p>GoJS 为用户交互提供了许多高级功能，例如拖放、复制和粘贴、就地文本编辑、工具提示、上下文菜单、自动布局、模板、数据绑定和模型、事务状态和撤消管理、调色板、概述、事件处理程序、命令和用于自定义操作的可扩展工具系统。</p></blockquote> <p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8aea0723eb364fdc8d0c3dc10296b659~tplv-k3u1fbpfcp-watermark.image?" alt="image.png"></p> <p>gojs能实现的效果比较多，相比较其他图形化的插件来说，功能相对于比较齐全，而且作为第一次接触来讲，虽然官网的文档的英文的，但是每个api都提供了具体的小实例，所以学习起来也算是比较方便，通过对一个个小demo就可以学习到完整的一些功能，今天主要就学习了几个简单的基础操作。</p> <p>实现在区域生成几个操作块，中间的操作块会循环指向周围的几个操作块，每秒会连接附近各个方块，指向对应的方块会变颜色。</p> <p><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/111d60bc94a74b6b84dc3327da0493f7~tplv-k3u1fbpfcp-watermark.image?" alt="image.png"></p> <p>实现的效果大概是一个时钟循环的类似效果。下面一起来看一下代码。</p> <h3 id="代码解析"><a href="#代码解析" class="header-anchor">#</a> 代码解析</h3> <p>与其他图形化插件一样，需要放置一个div作为我们的操作区域</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">//Html</span>
<span class="token operator">&lt;</span>div id<span class="token operator">=</span><span class="token string">&quot;myDiagramDiv&quot;</span>
style<span class="token operator">=</span><span class="token string">&quot;width:600px; height:350px; background-color: #DAE4E4;margin:100px auto&quot;</span><span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
</code></pre></div><p>通过<code>$(go.Diagram, &quot;myDiagramDiv&quot;)</code>将配置挂载到myDiagramDiv这个id的div上，有了如下配置</p> <p><code>diagram.nodeTemplate</code> 是方块的模板，声明这个模板后，创建多个方块的话，每个方块都会跟随当前模板的配置进行</p> <p><code>go.Node</code> 中对每个方块的属性做一些配置</p> <p><code>diagram.nodeTemplate</code> 是方块的模板，声明这个模板后，创建多个方块的话，每个方块都会跟随当前模板的配置进行</p> <p><code>location</code>声明方块的定位坐标，以第一个方块为中心点</p> <p><code>Shape</code>规定方块的形状</p> <p><code>fill</code>和<code>stroke</code>是对图形的填充和边框的属性</p> <p><code>TextBlock</code>是对内容进行填写，主要是针对边框中需要加的文字</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">//Html</span>
<span class="token function">$</span><span class="token punctuation">(</span>go<span class="token punctuation">.</span>Diagram<span class="token punctuation">,</span> <span class="token string">&quot;myDiagramDiv&quot;</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
<span class="token string-property property">&quot;undoManager.isEnabled&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span> 
<span class="token punctuation">}</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
diagram<span class="token punctuation">.</span>nodeTemplate <span class="token operator">=</span>
    <span class="token function">$</span><span class="token punctuation">(</span>go<span class="token punctuation">.</span>Node<span class="token punctuation">,</span> <span class="token string">&quot;Auto&quot;</span><span class="token punctuation">,</span>
      <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Binding</span><span class="token punctuation">(</span><span class="token string">&quot;location&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;loc&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>  <span class="token comment">// convert string into a Point value</span>
      <span class="token function">$</span><span class="token punctuation">(</span>
        go<span class="token punctuation">.</span>Shape<span class="token punctuation">,</span> <span class="token string">&quot;RoundedRectangle&quot;</span><span class="token punctuation">,</span>
        <span class="token punctuation">{</span> <span class="token literal-property property">fill</span><span class="token operator">:</span> <span class="token string">&quot;yellow&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">stroke</span><span class="token operator">:</span> <span class="token string">&quot;orange&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">strokeWidth</span><span class="token operator">:</span> <span class="token number">2</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Binding</span><span class="token punctuation">(</span><span class="token string">&quot;fill&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;highlight&quot;</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> v <span class="token operator">?</span> <span class="token string">&quot;pink&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;yellow&quot;</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Binding</span><span class="token punctuation">(</span><span class="token string">&quot;stroke&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;color&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">ofModel</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token function">$</span><span class="token punctuation">(</span>go<span class="token punctuation">.</span>TextBlock<span class="token punctuation">,</span>
        <span class="token punctuation">{</span> <span class="token literal-property property">margin</span><span class="token operator">:</span> <span class="token number">5</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Binding</span><span class="token punctuation">(</span><span class="token string">&quot;text&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;key&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">var</span> nodeDataArray <span class="token operator">=</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span> <span class="token literal-property property">key</span><span class="token operator">:</span> <span class="token string">&quot;.&quot;</span> <span class="token punctuation">,</span> <span class="token literal-property property">loc</span><span class="token operator">:</span> <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Point</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span>）<span class="token punctuation">,</span> <span class="token literal-property property">highlight</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{</span> <span class="token literal-property property">key</span><span class="token operator">:</span> <span class="token string">&quot;1&quot;</span> <span class="token punctuation">,</span> <span class="token literal-property property">loc</span><span class="token operator">:</span> <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Point</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">100</span>）<span class="token punctuation">,</span> <span class="token literal-property property">highlight</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{</span> <span class="token literal-property property">key</span><span class="token operator">:</span> <span class="token string">&quot;2&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">loc</span><span class="token operator">:</span> <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Point</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">0</span>）<span class="token punctuation">,</span> <span class="token literal-property property">highlight</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{</span> <span class="token literal-property property">key</span><span class="token operator">:</span> <span class="token string">&quot;3&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">loc</span><span class="token operator">:</span> <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Point</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">100</span>） <span class="token punctuation">,</span> <span class="token literal-property property">highlight</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{</span> <span class="token literal-property property">key</span><span class="token operator">:</span> <span class="token string">&quot;4&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">loc</span><span class="token operator">:</span> <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>Point</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">0</span>）<span class="token punctuation">,</span> <span class="token literal-property property">highlight</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">]</span><span class="token punctuation">;</span>
  <span class="token comment">// var linkDataArray = [</span>
  <span class="token comment">//   { from: &quot;.&quot;, to: &quot;1&quot; }</span>
  <span class="token comment">// ];</span>
  diagram<span class="token punctuation">.</span>model <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>GraphLinksModel</span><span class="token punctuation">(</span>nodeDataArray<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>接下来我们要多少个节点，就可以在节点数组中声明，由于设置了TextBlock中文字的属性是key，所以在key中设置需要填充的文字，loc也在location中做了配置，声明，所以我们就可以生成对应的位置和方块的颜色。</p> <p><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/915e5fe1875443eeb87ddf568c74de41~tplv-k3u1fbpfcp-watermark.image?" alt="image.png"></p> <h3 id="线条连接"><a href="#线条连接" class="header-anchor">#</a> 线条连接</h3> <p>接下来生成连接的线条</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">var</span> linkDataArray <span class="token operator">=</span> <span class="token punctuation">[</span>
<span class="token punctuation">{</span> <span class="token literal-property property">from</span><span class="token operator">:</span> <span class="token string">&quot;.&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">to</span><span class="token operator">:</span> <span class="token string">&quot;1&quot;</span> <span class="token punctuation">}</span>
<span class="token punctuation">]</span><span class="token punctuation">;</span>
</code></pre></div><p>表示从某个节点连接到对应的节点</p> <div class="language-js extra-class"><pre class="language-js"><code>  diagram<span class="token punctuation">.</span>model <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">go<span class="token punctuation">.</span>GraphLinksModel</span><span class="token punctuation">(</span>nodeDataArray<span class="token punctuation">,</span> linkDataArray<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>对应的挂载方式也要变更</p> <h3 id="让线条动起来"><a href="#让线条动起来" class="header-anchor">#</a> 让线条动起来</h3> <p>接下来让线条动起来，然后对应的变色</p> <p>由于我们在声明了<code>binding</code>监听节点属性的<code>highlight</code>，所以我们设置一个循环函数，在函数中用<code>m.set(node, &quot;highlight&quot;, !nodeData.highlight)</code>轮流给每个方块更换<code>heightlight</code>的节点属性，并且用<code>setToKeyForLinkData</code>指向对应的需要连接的方块，<code>linkData</code>我们指定了为<code>m.linkDataArray[0]</code>,所以每次都是从第一个开始连接，每次通过<code>min</code>进行自增，循环调用loop函数，达到了旋转连线的效果</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">let</span> min <span class="token operator">=</span> <span class="token number">1</span>
  <span class="token keyword">function</span> <span class="token function">switchTo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

    diagram<span class="token punctuation">.</span>model<span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">m</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">var</span> linkData <span class="token operator">=</span> m<span class="token punctuation">.</span>linkDataArray<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
      nextNode <span class="token operator">=</span> nodeDataArray<span class="token punctuation">[</span>min<span class="token punctuation">]</span><span class="token punctuation">.</span>key
      <span class="token keyword">var</span> nodeData <span class="token operator">=</span> m<span class="token punctuation">.</span>nodeDataArray 
      <span class="token keyword">var</span> node <span class="token operator">=</span> nodeData<span class="token punctuation">[</span>min<span class="token punctuation">]</span>
      <span class="token comment">// console.log(nodeData,'nodeData')</span>
      <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token keyword">of</span> nodeData<span class="token punctuation">)</span><span class="token punctuation">{</span>
          m<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span>i<span class="token punctuation">,</span> <span class="token string">&quot;highlight&quot;</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
      m<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span>node<span class="token punctuation">,</span> <span class="token string">&quot;highlight&quot;</span><span class="token punctuation">,</span> <span class="token operator">!</span>nodeData<span class="token punctuation">.</span>highlight<span class="token punctuation">)</span><span class="token punctuation">;</span>
      m<span class="token punctuation">.</span><span class="token function">setToKeyForLinkData</span><span class="token punctuation">(</span>linkData<span class="token punctuation">,</span> nextNode<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    min <span class="token operator">==</span> <span class="token number">4</span> <span class="token operator">?</span> min <span class="token operator">=</span> <span class="token number">1</span> <span class="token operator">:</span> min<span class="token operator">++</span>

  <span class="token punctuation">}</span>
  <span class="token keyword">function</span> <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token function">switchTo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token function">loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0815aa2406f84ae3b6ff8e5c95f46035~tplv-k3u1fbpfcp-watermark.image?" alt="image.png"></p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023-01-04 10:56:12</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/posts/项目问题解决/eltable.html" class="prev">
        el-table自定义表头及无数据状态
      </a></span> <span class="next"><a href="/posts/项目问题解决/react踩坑.html">
        React踩坑
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----><!----></div></div>
    <script src="/assets/js/app.6514719e.js" defer></script><script src="/assets/js/2.ea114ffb.js" defer></script><script src="/assets/js/45.870a7650.js" defer></script><script src="/assets/js/4.e093c564.js" defer></script>
  </body>
</html>
